package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.model.Order;
import com.example.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lbq
 * @version 1.0
 * @date 2021/5/16 12:59
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/add/{num}")
    public Boolean add(@PathVariable("num") Integer num) {
        try {
            orderService.add(num);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @GetMapping("/getOrder/{userId}")
    public List<Order> getOrderByUserId(@PathVariable("userId") Integer userId) {
        return orderService.list(new QueryWrapper<>(new Order()).eq("user_id", userId));
    }
}
